package linda.test;

import java.util.Collection;

import linda.Linda;
import linda.Tuple;

public class BasicTestRMI6 {
	 public static void main(String[] a) {
			
	        final Linda linda = new linda.server.LindaClient("localhost");
	        // final Linda linda = new linda.server.LindaClient("//localhost:4000/aaa");
			
	        new Thread() {
	            public void run() {
	                try {
	                    Thread.sleep(2000);
	                } catch (InterruptedException e) {
	                    e.printStackTrace();
	                }
	                Tuple motif = new Tuple(Integer.class, Integer.class);
	                System.out.println("Test de readall");
	                
	                Collection<Tuple> list_tuple;
	                list_tuple = linda.readAll(motif);

	                if (list_tuple.isEmpty()){
	                	System.out.println("Le readall est vide");
	                }
	                else {
	                	for (Tuple t : list_tuple){ 
	                		System.out.println("valeur tuple : " + t);
	                	}
	                	System.out.println("Vérification éléments présents en mémoire");
	                    Tuple res;
	                	list_tuple = linda.takeAll(motif);
	                	if (list_tuple.isEmpty()){
	                		System.out.println("Erreur pendant le takeall");
	                	}
	                	else {	
	                	     res = linda.tryTake(motif);
	                	     if (res == null)
	                    	     System.out.println("il n'y a plus rien en mémoire");
	                	}
	                }
	            }
	        }.start();
			
	        new Thread() {
	            public void run() {
	                try {
	                    Thread.sleep(2);
	                } catch (InterruptedException e) {
	                    e.printStackTrace();
	                }

	                Tuple t1 = new Tuple(4, 5);
	                System.out.println("(2) write: " + t1);
	                linda.write(t1);

	                Tuple t11 = new Tuple(2, 9);
	                System.out.println("(2) write: " + t11);
	                linda.write(t11);
	                
	                Tuple t2 = new Tuple(7, 8);
	                System.out.println("(2) write: " + t2);
	                linda.write(t2);

	                Tuple t21 = new Tuple(1, 5);
	                System.out.println("(2) write: " + t21);
	                linda.write(t21);
					
	                linda.debug("(2)");

	            }
	        }.start();
			
	    }
}
